//componente que crea calendarios,permitiendo el ingreso de infomación opr dias- meses- años- hora de inicio y de fin
//contenedor principal del calendario
var xCalendar;
//Nombre del contenedor del calendario
var container;
//controla la informacion de los eventos
var xEvents;
//indica la direccion donde se encuentra la pagina de edicion
var calendaredit;
//indica la direccion de la pagina quecrea l aconsulta para obtener los datos
var urldata;
//indica cual vista se esta mostrando 0:mes, 1:semana, 2:dia
var wshow;
//contador auxiliar
var contd;
function WebCalendar()
{
	xCalendar= new xWebCalendar();
	xEvents= new  lEvents();
	xEvents.Create();
	//inicializa el calendario
	xCalendar= new xWebCalendar();
	this.show = function(){
		
		
		$.get(urldata,{Month:new Date().getMonth()+1,Year:new Date().getFullYear()},
			function(data){
			eval(data);			
			xCalendar.drawCalendar();
			//indica que se inicia en mes
			wshow==0;
			xCalendar.showDiary();
			
			}
		);
		
	}

}

function xWebCalendar(){

	//contiene el dia actual
	var today;
	this.today = new Date().getUTCDate();
	//contiene el mes que se esta mostrando 
	var xday;
	this.xday = new Date().getUTCDate();
	//contiene el mes actual	
	var month;
	this.month = new Date().getMonth();
	//Contiene el Mes que se esta mostrando
	var xmonth;
	this.xmonth = new Date().getMonth();
	;
	//contiene el año actual;
	var year;
	this.year = new Date().getFullYear();
	//contiene el año que se esta mostrando
	var xyear;
	this.xyear = new Date().getFullYear();
	//contiene los meses del año
	var monthyear;
	this.monthyear = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];
	//contiene la cantidad de dias del mes
	var monthdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	//contiene los dias dela semana
	var weekday;
	this.weekday= ["Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"];
	//contenedor de del calendario
	var content;
	//encabezado de calendario
	var head;
	//headoptions;
	var headmenu;
	//headdate
	var dateoptions;
	//obtiones de avance y retroceso
	var nextbutton;
	var backbutton;
	var headdate;
	var todaybutton;
	//opciones de busqueda
	var search;
	var searchbutton;
	var searchinput;
	//contenedores que muestran los detalles del dia
	var show;
	var headshow
	var contentshow;
	//funcion que dibuja el encabezado del calendario
	this.drawCalendar = function(){
		container = $("#" + container);
		container.css("float","left");
		container.css("width","80%");
		this.head = $(document.createElement("div"));
		this.head.attr("id", "headcalendar");
		//contenedor de las opciones de calendario		
		this.headmenu = $(document.createElement("div"));
		this.headmenu.attr("id", "calendarmenu");
		//contenedor de la fecha de calendario		
		this.dateoptions = $(document.createElement("div"));
		this.dateoptions.attr("id", "calendaroptions");
		//agrega los div a head
		this.head.append(this.dateoptions);
		this.head.append(this.headmenu);
		
		this.content = $(document.createElement("div"));
		this.content.attr("id", "contentcalendar");
		container.html(this.head);
		container.append(this.content);
		//crea la opciones del menu
		var ul = $(document.createElement("ul"));
		var liday = $(document.createElement("li"));
		liday.html("D&iacute;a");
		liday.attr("onClick", "xCalendar.showDay()");
		
		var liweek = $(document.createElement("li"));
		liweek.html("Semana")
		liweek.attr("onClick", "xCalendar.showWeek()");
		
		var limonth = $(document.createElement("li"));
		limonth.html("Mes");
		limonth.attr("onClick", "xCalendar.showMonth()");
		
		var lidiary = $(document.createElement("li"));
		lidiary.html("Agenda");
		lidiary.attr("onClick", "xCalendar.showDiary()");
		
		ul.append(liday);
		ul.append(liweek);
		ul.append(limonth);
		ul.append(lidiary);
		
		//this.headmenu.append(ul);
		
		//crea las flechas
		this.nextbutton = $(document.createElement("div"));
		this.nextbutton.attr("id", "nextbutton");
		//
		this.backbutton = $(document.createElement("div"));
		this.backbutton.attr("id", "backbutton");
		//devuelve a la fecha actual
		var div=$(document.createElement("div"));
		div.attr("id","todayop");
		
		this.todaybutton=$(document.createElement("input"));
		this.todaybutton.attr("type","button");
		this.todaybutton.attr("value","Hoy");
		
		div.html(this.todaybutton);
		this.headdate = $(document.createElement("div"));
		this.headdate.attr("id", "headdate");
		//
		//this.dateoptions.append(this.backbutton);
		//this.dateoptions.append(this.nextbutton);
		//this.dateoptions.append(div);
		//this.dateoptions.append(this.headdate);
		//
		this.search=$(document.createElement("div"));
		this.search.attr("id","searchdate");
		
		this.searchbutton=$(document.createElement("input"));
		this.searchbutton.attr("type","button");
		this.searchbutton.attr("value","Buscar");
		this.searchbutton.attr("class","btn");
		this.searchbutton.attr("onClick","xCalendar.Search()");
		
		this.searchinput=$(document.createElement("input"));
		this.searchinput.attr("type","text");
		this.searchinput.attr("id","txtsearchdate");
		this.searchinput.attr("class","texto");
		
		this.search.append(this.searchinput);
		this.search.append(this.searchbutton);
		this.head.append(this.search);
				
		//contenedor
		this.show=$(document.createElement("div"));		
		this.show.attr("id","showevent");
		//encabezado
		this.headshow=$(document.createElement("div"));	
		this.headshow.attr("id","headshow");	
		//contenido
		this.contentshow=$(document.createElement("div"));
		this.contentshow.attr("id","contentshow")
		this.contentshow.html(" ")
				//contenedor que muestra los eventos en detalle
		var headshowx=$(document.createElement("div"));	
		headshowx.attr("id","headshowx");
		headshowx.attr("onClick","xCalendar.closeShow()");
		headshowx.html("x");
			
		var headshowt=$(document.createElement("div"));	
		headshowt.attr("id","headshowt");
			
	
		this.headshow.append(headshowt);
		this.headshow.append(headshowx);
	}
	this.showdays=function(xyear,xmonth,xday)
	{
		this.xday=xday;
		this.xmonth=xmonth;
		this.xyear=xyear;
		this.showDay();
	}
	
	//funcion que muestra la información de un dia
	this.showDay = function(){
		wshow=2;
		xCalendar.nextbutton.attr("onClick", "xCalendar.nextday()");
		xCalendar.backbutton.attr("onClick", "xCalendar.backday()");
		xCalendar.todaybutton.attr("onClick", "xCalendar.gotoday()");
		
		//encabezado del dia
		this.headdate.html(this.xday + " de " + this.monthyear[this.xmonth] + ", " + this.xyear);
		//contenedor del dia
		var day = $(document.createElement("div"));
		day.attr("id", "showday")
		//crea una tabla que muestra el dia
		var xtable = $(document.createElement("table"));
		for (i = 1; i < 24; i++) {
			//contenedor de una hora
			var tr = $(document.createElement("tr"));
			//información de la hora
			var tdhora = $(document.createElement("td"));
			tdhora.attr("class", "hour")
			if (i <= 12) 
				tdhora.html(i + ":00 am");
			else 
				tdhora.html((i - 12) + ":00 pm");
			//información de contendor de la información 
			var tdinfo = $(document.createElement("td"));
			tdinfo.attr("class", "hday");
			tdinfo.attr("id", "hour" + i)
			
			
			tr.append(tdhora);
			tr.append(tdinfo);
			xtable.append(tr);
		}
		day.html(xtable);
		this.content.html(day);
		document.getElementById('hour7').scrollIntoView(true);
		
		this.loadDataDay();
	}	
	//obtiene y mustra la información de los eventos
	this.loadDataDay = function(){
		//obtiene los eventos del dia
		events = xEvents.getDayEvents(this.xyear,this.xmonth + 1, this.xday);
		while (events != null) {
			hinit = events.hourinit.split(":");
			//contenedor de los eventos
			var div = $(document.createElement("div"));
			div.attr("id", "eventinfo");
			//hora de inicio
			var hi = $(document.createElement("div"));
			hi.attr("id", "hstarevent");
			hour=events.hourinit.split(":");
			if(hour[0] > 13)
				hi.html((hour[0]-12)+":"+hour[1]+"pm");
			else
				hi.html(events.hourinit+"am");
			//hora final
			var hf = $(document.createElement("div"));
			hf.attr("id", "hendevent");
			hour=events.hourend.split(":");
			if(hour[0] > 13)
				hf.html("&nbsp;-&nbsp;"+(hour[0]-12)+":"+hour[1]+"pm");
			else	
				hf.html("-" + events.hourend+"am");
			//nombre
			var name = $(document.createElement("div"));
			name.attr("id", "nameevent");
			name.html(events.name);
			//descripcion
			var descr = $(document.createElement("div"));
			descr.attr("id", "descevent");
			descr.html(events.description);
			//lugar del evento
			var place = $(document.createElement("div"));
			place.attr("id", "placeevent");
			place.html("Ubicacion: " + events.place);
			//link de evitar
			var _link = $(document.createElement("div"));
			_link.attr("id", "linkeditevent");
			var al = $(document.createElement("a"));
			al.attr("href", calendaredit + "?evento=" + events.idevent);
			al.html("Editar");
			_link.html(al)
			//agrega los eventos
			div.append(hi);
			div.append(hf);
			div.append(name);
			div.append(descr);
			div.append(place);
			if(events.edit)
				div.append(_link);
			$("#hour" + hinit[0]).append(div);
			list = events.lEvents;
			
			events = events.next;
		}
	}
	//avanza al siguiente dia del evento
	this.nextday = function(){
		this.xday++;
		if (this.xday > this.daysInMonth(this.xyear, this.xmonth)) {
			this.xday = 1;
			this.addmonth();
			
			
		}
		xCalendar.showDay();
	}
	//retrocede un dia del evento
	this.backday = function(){
		this.xday--;
		if (this.xday == 0) {
			this.removemonth();			
			this.xday = this.daysInMonth(this.xyear, this.xmonth);
		}
		xCalendar.showDay();
	}
	//retorna l dia actual
	this.gotoday=function()
	{
		this.xmonth=this.month;
		this.xday=this.today;
		this.xyear=this.year;
		xCalendar.showDay();
	}
	//funcion que muestra la información de una semana
	this.showWeek = function(){
		wshow=1;
		xCalendar.nextbutton.attr("onClick", "xCalendar.nextweek()");
		xCalendar.backbutton.attr("onClick", "xCalendar.backweek()");
		xCalendar.todaybutton.attr("onClick", "xCalendar.goweek()");
		var week = $(document.createElement("div"));
		week.attr("id", "showweek");
		//obtiene la cantidad de dias de mes anterior
		xmonth = this.daysInMonth(this.xyear, this.xmonth);
		
		dat = new Date();
		dat.setFullYear(this.xyear, this.xmonth, this.xday);
		
		nday = dat.getDay();
		n = this.xday - nday;
		nmonth = this.xmonth;
		//si n es menor que uno indica que tiene dias del mes anterior
		//por lo tando se consulta para determinar el valor de n
		xmonth = this.daysInMonth(this.xyear, this.xmonth);
		if (n < 1) {
			this.removemonth();
			
			
			if (this.xmonth == 0) {
				xmonth = 31;
			}
			nmonth = this.xmonth;
			xmonth = this.daysInMonth(this.xyear, this.xmonth);
			n = xmonth - (-1 * n);
		}
		
		//auxiliar
		nn = n;
		xyear=this.xyear;
		//encabezado de la semana
		var headweek = $(document.createElement("div"));
		headweek.attr("id", "headweek");
		//crea el encabezado de los titulos
		for (i = 0; i < 8; i++) {
		
			var div = $(document.createElement("div"));
			div.attr("class", "title");
			//indica que se exedio en los dia que posee el mes
			if (n > xmonth) {
				n = 1;
				//incrementa el mes
				this.xmonth++;
				if(this.xmonth>=12)
				{
					this.xmonth=0;
					this.addYear();
					this.xday=1;
				}
				this.getDataMonth();				
				
		
			}
			if (i > 0) {
				div.html(this.weekday[i-1]+"&nbsp;"+n);
				n++;
			}
			else {
				div.attr("class", "xhour");
				div.html("&nbsp");
			}
			headweek.append(div);
		}
		n--;
		//this.xday = n;
		this.headdate.html(nn + " de " + this.monthyear[nmonth] + " - " + n + " de " + this.monthyear[this.xmonth]);
		
		
		week.append(headweek);
		//contenido de la semana
		var content = $(document.createElement("div"));
		content.attr("id", "contentweek");
		var xtable=$(document.createElement("table"));
		for (i = 1; i < 24; i++) {
			c = nn;
			var tr = $(document.createElement("tr"));
			for (n = 0; n < 8; n++) {
				var td = $(document.createElement("td"));
				if (n > 0) {
					//carga las horas y dias
					td.attr("class", "xhourd");
					td.attr("id", "d" + c + "h" + i);
					td.html("&nbsp");
					if (c >= xmonth) 
						c = 0;
					
					c++;
				}
				else {
					//muestra las horas al lado izq del calendario
					td.attr("class", "xhour");
					if (i < 13) {
						td.html(i + ":00 am");
					}
					else {
						td.html((i - 12) + ":00 pm");
					}
					td.attr("id", "xhour" + i);
				}
				
				tr.append(td);
			}
			xtable.append(tr);
		}
		content.append(xtable);
		week.append(content);
		this.content.html(week);
		
		n = nn;
		//agrega la información de los eventos
		for (i = 0; i < 8; i++) {
			if (n > xmonth) {
				n=1;
				nmonth++;
				if(nmonth==12)
				{
					nmonth=0;
					xyear++;
				}
			}
			
			this.loadDataDayWeek(xyear,nmonth,n);
			n++;
		}
		document.getElementById('xhour7').scrollIntoView(true);
		
	}
	//carga los eventos de una semana
	this.loadDataDayWeek = function(year,month, day){
		//obtiene los eventos del dia
		events = xEvents.getDayEvents(year,month + 1, day);
		while (events != null) {
			hinit = events.hourinit.split(":");
			//contenedor de los eventos
			var div = $(document.createElement("div"));
			div.attr("id", "eventinfo");
			//hora de inicio
			var hi = $(document.createElement("div"));
			hi.attr("id", "hstarevent");
			hour=events.hourinit.split(":");
			if(hour[0] > 13)
				hi.html((hour[0]-12)+":"+hour[1]+"pm");
			else
				hi.html(events.hourinit+"am");
			//hora final
			var hf = $(document.createElement("div"));
			hf.attr("id", "hendevent");
			hour=events.hourend.split(":");
			if(hour[0] > 13)
				hf.html("&nbsp;-&nbsp;"+(hour[0]-12)+":"+hour[1]+"pm");
			else	
				hf.html("-" + events.hourend+"am");
			//nombre
			var name = $(document.createElement("div"));
			name.attr("id", "nameevent");
			name.html(events.name);
			//agrega los eventos
			div.append(hi);
			div.append(hf);
			div.append(name);
			$("#d" + day + "h" + hinit[0]).append(div);			
			events = events.next;
		}
		
	}
	//avanza a la semana siguiente
	this.nextweek = function(){
		this.xday += 7;
		xday = this.daysInMonth(this.xyear, this.xmonth);
		if (this.xday > xday) {
			this.addmonth();
			
			this.xday = this.xday - xday;
			
			
		}
		xCalendar.showWeek();
	}
	//retorna una semana
	this.backweek = function(){
		this.xday -= 7;
		
		if (this.xday < 1) {
			this.removemonth();
			
			this.xday = this.daysInMonth(this.xyear, this.xmonth) - 7;
		}
		xCalendar.showWeek();
	}
	//retorna l dia actual
	this.goweek=function()
	{
		this.xmonth=this.month;
		this.xday=this.today;
		this.xyear=this.year;
		xCalendar.showWeek();
	}
	//muestra la informacion de un mes
	this.showMonth=function()
	{
		wshow=0;
		xCalendar.nextbutton.attr("onClick", "xCalendar.nextmonth()");
		xCalendar.backbutton.attr("onClick", "xCalendar.backmonth()");
		xCalendar.todaybutton.attr("onClick", "xCalendar.gomonth()");
		this.headdate.html( this.monthyear[this.xmonth]+", "+this.xyear );
		var showmonth=$(document.createElement("div"));
		showmonth.attr("id","showmonth");
		
		//tabla que contiene el mes
		var xtable=$(document.createElement("table"));
		var tr=$(document.createElement("tr"));
		//encabezado
		for(k=0;k<7;k++)
		{
			var th=$(document.createElement("th"));
			th.html(this.weekday[k]);
			tr.append(th);
		}
		xtable.append(tr);
		//imprime los dias del mes
		//semanas del mes
		
		mdate= new Date();
		mdate.setFullYear(this.xyear,this.xmonth,1);
		s=mdate.getDay();
		w=((this.daysInMonth(this.xyear,this.xmonth))/7);
		w=Math.round(w);
		//verifica si el resultado ue entero o de lo contrario agraga 1
		if(s>=5)
		{
				w++;
		}
		
		m=this.daysInMonth(this.xyear,this.xmonth);
		b=0;
		d=1;
		//establece la fecha
		dat = new Date();
		dat.setFullYear(this.xyear, this.xmonth, 1);
		//optiene el dia de las semana del primer dia
		n=dat.getDay();
		
		for(k=0;k<=w;k++)
		{
			//contenedor de una semana
			var tr = $(document.createElement("tr"));
			for (z = 0; z < 7; z++) {
				//crea el contenedor del dia
				var td = $(document.createElement("td"));
				//agrega la informaci´n a las tablas que les corresponden dias
				if(b>=n && b<(m+n)){
					//encabezado 
					var divh=$(document.createElement("div"));
					divh.attr("class","headdaymonth");
					divh.html(d);
					//contenedor
					var divc=$(document.createElement("div"));
					divc.attr("id","mday"+d);
					divc.attr("class","xdaymonth");
					divc.html("<ul/>");	
					td.append(divh);
					td.append(divc);
					td.attr("onClick","xCalendar.showdays("+this.xyear+","+this.xmonth+","+d+");");
					d++;
				}
				if(z==0)
						td.attr("class","sundaymonth");
					else	
						td.attr("class","daymonth");
				b++;
				tr.append(td);
				
			}
			xtable.append(tr);
		}
		showmonth.html(xtable);
		this.content.html(showmonth);
		
		this.loadDataMonth();
	}
	//carga los eventos del mes
	this.loadDataMonth=function()
	{
		
		lmonth=xEvents.getMonthEvents(this.xyear,this.xmonth+1);
		
		while(lmonth){
			var xday=lmonth;
			cont=0;
			if (xday != null) {
				ul=$("#mday"+xday.day+" ul");
				var event=xday.lEvents;
				while (event != null && cont<5) {
					//hora de inicio
					var hi = $(document.createElement("div"));
					hi.attr("id", "hstarevent");
					hour=event.hourinit.split(":");
					if(hour[0] > 13)
						hi.html((hour[0]-12)+":"+hour[1]+"pm");
					else
						hi.html(event.hourinit+"am");
					
					//nombre del evento	
					var dive=$(document.createElement("div"));
					dive.attr("id","nameevent");
					dive.html(" - "+event.name);
					
					var li=$(document.createElement("li"));
					li.append(hi);					
					li.append(dive);
					ul.append(li);
					event = event.next;
					cont++;
				}
			}
			lmonth=lmonth.next;
		}
	}
	//avanza al siguiente mes
	this.nextmonth=function()
	{
		this.addmonth();
		
		xCalendar.showMonth();
	}
	//retrocede un mes
	this.backmonth=function()
	{
		this.removemonth();
		
		xCalendar.showMonth();
	}
	//retorna l dia actual
	this.gomonth=function()
	{
		this.xmonth=this.month;
		this.xday=this.today;
		this.xyear=this.year;
		xCalendar.showMonth();
	}
	//aumente en un mes
	this.addmonth=function()
	{
		this.xmonth++;
		if(this.xmonth>=12)
		{
			this.xmonth=0;
			this.addYear();
		}
		this.getDataMonth();
	}
	//aumente en un mes
	this.removemonth=function()
	{
		this.xmonth--;
		if(this.xmonth<=-1)
		{
			this.xmonth=11;
			this.removeYear();
		}
		this.getDataMonth()	;
	}
	//obtiene los eventos representantes a un mes
	this.getDataMonth=function()
	{
		lmonth=xEvents.getMonthEvents(this.xyear,this.xmonth+1);
		if(lmonth==null)
		{
			$.get(urldata,{Month:this.xmonth+1,Year:this.xyear},
			function(data){
				eval(data);			
				if(wshow==0)
					xCalendar.loadDataMonth();
				if(wshow==1)	
					xCalendar.showWeek();
				if(wshow==2)	
					xCalendar.loadDataDay();	
			
			}
		);
		}
	}
	////muestra la informacion de la agenda
	this.showDiary=function()
	{
		wshow=0;
	/*	xCalendar.nextbutton.attr("onClick", "");
		xCalendar.backbutton.attr("onClick", "");
		xCalendar.todaybutton.attr("onClick", "");*/
		//encabezado de la agenda
		var agenda=$(document.createElement("div"));
		agenda.attr("id","headagenda");		
		agenda.html("Agenda")
		//contenido de la agenda
		var acontent=$(document.createElement("div"));
		acontent.attr("id","contentagent")
		
		//tabla
		var xtable=$(document.createElement("table"));
		xtable.attr("id","tablediary");
		var tr=$(document.createElement("tr"));
		
		//
		th=$(document.createElement("th"));
		th.attr("class","date");
		th.html("Fecha");
		//
		th2=$(document.createElement("th"));
		th2.attr("class","event");
		th2.html("Evento");
		//
		th3=$(document.createElement("th"));
		th3.attr("class","hour");
		th3.html("Hora");
		
		tr.append(th);
		tr.append(th3);
		tr.append(th2);
		
		xtable.append(tr);
		
		acontent.html(xtable);
		this.content.html("");
		this.content.append(agenda);
		this.content.append(acontent);
		xyear=this.year;
		xmonth=this.month;
		contd = 0;
		months=[];
		years=[];
		for (m = 0; m < 3; m++) {
			//carga los eventos del mes
			lmonth = xEvents.getMonthEvents(xyear, xmonth + 1);
			//si el mes es nulo busca el siguiente
				if(lmonth==null)
				{
					months[m-1]=xmonth;
					years[m-1]=xyear;
					$.get(urldata,{Month:xmonth+1,Year:xyear},
					function(data){
						eval(data);			
						lmonth = xEvents.getMonthEvents(years[0], months[0] + 1);	
						xCalendar.loadDataDiary(lmonth, months[0]+1,years[0]);
						years[0]=years[1];
						months[0]=months[1];	
						
					}
				);
				}
				else{
					this.loadDataDiary(lmonth,xmonth+1,xyear);
				}
					xmonth++;
					if(xmonth==12)
					{
						xmonth=0;
						xyear++;
					}
			
			
			
		}
		
		
		
		
		
		//cargar otros meses
		
	}
	//carga los eventos del mes en la agenda
	this.loadDataDiary=function(lmonth,xmonth,xyear)
	{
		var xtable=$("#tablediary");
		
		//contenido de la agenda
		var acontent=$("#contentagent");		
		while (lmonth!=null) {
				var xday = lmonth;
				
				if (xday != null) {
					var event = xday.lEvents;
					while (event != null) {
					
						var tre = $(document.createElement("tr"));
						var tddate = $(document.createElement("td"));
						var tdevent = $(document.createElement("td"));
						var tdhour = $(document.createElement("td"));
						
						//link de edición						
						var _link = $(document.createElement("div"));
						_link.attr("class", "linkedit");
						var al = $(document.createElement("a"));
						al.attr("href", calendaredit + "?evento=" + event.idevent);
						al.html("Editar");
						_link.html(al)
						
						
						var link= $(document.createElement("a"));
						link.attr("onClick","xCalendar.showEvent("+event.idevent+");");
						link.attr("class","link");
						link.html(event.name);
						if(event.edit)
						link.append(_link);
						//idevent
						
						if ((contd % 2) == 0) {
							tddate.attr("class", "date1");
							tdevent.attr("class", "event1");
							tdhour.attr("class", "hour1");
						}
						else {
							tddate.attr("class", "date2");
							tdevent.attr("class", "event2");
							tdhour.attr("class", "hour2");
						}
						tddate.html(xday.day + "/" + (xmonth) + "/" + xyear)
						tdevent.html(link);
						
						
						//hora de inicio
						var hi = $(document.createElement("div"));
						hi.attr("id", "hstarevent");
						hour = event.hourinit.split(":");
						if (hour[0] > 13) 
							tdhour.html((hour[0] - 12) + ":" + hour[1] + " pm");
						else 
							tdhour.html(event.hourinit + " am");
						
						tre.html(tddate);
						tre.append(tdhour);
						tre.append(tdevent);
						xtable.append(tre);
						
						
						event = event.next;
						contd++;
					}
				}
				lmonth = lmonth.next;
			}
		acontent.html(xtable);
		
		
			
	}
	this.Search=function()
	{
		var acontent=$("#contentagent");	
		txts=$("#txtsearchdate").val();
			$.get("../Consultas/Calendar.php",{text:txts},
					function(data){
							acontent.html(data);	
					}
				);
		
	}
	//
	//determina la cantidad de dias de un mes
	//year indica el año en 4 digitos, month el numero del mes  de 1 a 12
	this.daysInMonth = function(_year, _month)
	{
		if ((_month == 1) && (_year % 4 == 0)) {
			return 29;
		}
		else {
			return monthdays[_month];
		}
	}
	this.addYear = function(){
		this.xyear++;
	}
	this.removeYear=function()
	{
		this.xyear--;
	}
	
	
	//muestra en una ventana la descripción del evento
	this.showEvent=function(idevent)
	{
		this.show.append(this.headshow);	
		this.show.append(this.contentshow);	
		this.content.append(this.show);
		
		this.show.hide();
		
		this.headshow.mousedown(function(e){
			xCalendar.show.easydrag("enable");
		}).mouseup(function(e){
			
		});
		
		$.get("../Consultas/curso.php",{event:idevent},
				function(data){
					   var event=data.split("|");
						xCalendar.contentshow.html("");
						
						var lblname=$(document.createElement("label"));
						lblname.html("Nombre :");
						
						var divname=$(document.createElement("div"));
						divname.attr("class","txt");
						divname.html(event[0]);
						
						var lbllugar=$(document.createElement("label"));
						lbllugar.html("Lugar :");
						
						var divplace=$(document.createElement("div"));
						divplace.attr("class","txt");
						divplace.html(event[1]);
						
						var lblfecha=$(document.createElement("label"));
						lblfecha.html("Fecha :");
						
						var divdate=$(document.createElement("div"));
						divdate.attr("class","txt");
						divdate.html(event[3]);
						
						var lblhorai=$(document.createElement("label"));
						lblhorai.html("Hora :");		
						
						var divhora=$(document.createElement("div"));
						divhora.attr("class","txt");
						divhora.html(event[4]+" - "+event[5]);
						
						var lbldesc=$(document.createElement("label"));
						lbldesc.html("Descripci&oacute;n :");
						
						var divdesc=$(document.createElement("div"));
						divdesc.attr("class","txt");
						divdesc.html(event[2]);
						
						$("#headshowt").html(event[0]);
						
						xCalendar.contentshow.append(lblname);
						xCalendar.contentshow.append(divname);
						xCalendar.contentshow.append(lbllugar);
						xCalendar.contentshow.append(divplace);
						xCalendar.contentshow.append(lblfecha);
						xCalendar.contentshow.append(divdate);
						xCalendar.contentshow.append(lblhorai);
						xCalendar.contentshow.append(divhora);
						xCalendar.contentshow.append(lbldesc);						
						xCalendar.contentshow.append(divdesc);
						
						xCalendar.show.show();
						if (!$.browser.msie) {
						
							xCalendar.contentshow.corner();
							xCalendar.headshow.corner();
							xCalendar.show.corner();
						}
				}
		);
	}
	this.closeShow=function()
	{
		this.show.hide();
	}
}


